package cn.witsky.cdrService.request;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import cn.witsky.cdrService.SpringContextHolder;
import cn.witsky.cdrService.config.AsnMoCallConfig;
import cn.witsky.cdrService.constant.ValType;
import cn.witsky.cdrService.domain.base.Value;
import cn.witsky.cdrService.domain.callEvent.MoCall;

public class MoCallRequest extends AsnMoCallConfig {
	private static Logger logger = LoggerFactory.getLogger(MoCallRequest.class);
	private String servedMSISDN;
	private String callingNumber;
	private String calledNumber;
	private String setupTime;
	private String alertingTime;
	private String answerTime;
	private String releaseTime;
	private String callDuration;
	private String callReference;
	
	String servedIMEI="";
	String translatedNumber="";
	String gsmSCFAddress="";
	String serviceKey="";
	String numberOfDPEncountered="";
	String levelOfCAMELService="";
	String classmark3="";
	String mscOutgoingCircuit="";
	String lastmccmnc="";
	public String getServedMSISDN() {
		return servedMSISDN;
	}

	public void setServedMSISDN(String servedMSISDN) {
		this.servedMSISDN = servedMSISDN;
	}

	public String getCallingNumber() {
		return callingNumber;
	}

	public void setCallingNumber(String callingNumber) {
		this.callingNumber = callingNumber;
	}

	public String getCalledNumber() {
		return calledNumber;
	}

	public void setCalledNumber(String calledNumber) {
		this.calledNumber = calledNumber;
	}

	public String getSetupTime() {
		return setupTime;
	}

	public void setSetupTime(String setupTime) {
		this.setupTime = setupTime;
	}

	public String getAlertingTime() {
		return alertingTime;
	}

	public void setAlertingTime(String alertingTime) {
		this.alertingTime = alertingTime;
	}

	public String getAnswerTime() {
		return answerTime;
	}

	public void setAnswerTime(String answerTime) {
		this.answerTime = answerTime;
	}

	public String getReleaseTime() {
		return releaseTime;
	}

	public void setReleaseTime(String releaseTime) {
		this.releaseTime = releaseTime;
	}
	
	public String getCallDuration() {
		return callDuration;
	}

	public void setCallDuration(String callDuration) {
		this.callDuration = callDuration;
	}

	public String getCallReference() {
		return callReference;
	}

	public void setCallReference(String callReference) {
		this.callReference = callReference;
	}
	
	public void setDefaultVal() {
		AsnMoCallConfig asnMoCallConfig=SpringContextHolder.getBean(AsnMoCallConfig.class);
		BeanUtils.copyProperties(asnMoCallConfig, this);
	}
	public MoCall covertMoCall() {
		this.setDefaultVal();
		if (!this.validate()) {
			logger.warn("缺少必填项......");
			return null;
		}
		MoCall moCall=new MoCall();
		Value val = new Value();
		val.setType(ValType.NONE);
		val.setValStr(this.getCallType());
		moCall.getRecordType().setValBytes(val);

		val.setType(ValType.TBCD);
		val.setValStr(this.getServedIMSI());
		moCall.getServedIMSI().setValBytes(val);

		val.setType(ValType.TBCD);
		val.setValStr(this.servedIMEI);
		moCall.getServedIMEI().setValBytes(val);

		val.setType(ValType.TBCD);
		val.setPrefix("91");
		val.setValStr(this.getServedMSISDN());
		moCall.getServedMSISDN().setValBytes(val);

		val.setType(ValType.TBCD);
		val.setPrefix("A1");
		val.setValStr(this.getCallingNumber());
		moCall.getCallingNumber().setValBytes(val);

		val.setType(ValType.TBCD);
		val.setPrefix("81");
		val.setValStr(this.getCalledNumber());
		moCall.getCalledNumber().setValBytes(val);

		val.setType(ValType.TBCD);
		val.setPrefix("A1");
		val.setValStr(this.translatedNumber);
		moCall.getTranslatedNumber().setValBytes(val);

		val.setType(ValType.TBCD);
		val.setPrefix("91");
		val.setValStr(this.getRecordingEntity());
		moCall.getRecordingEntity().setValBytes(val);

		val.setType(ValType.ASCII);
		val.setValStr(this.getMscIncomingROUTE());
		moCall.getMscIncomingROUTE().getMscIncomingRouteVal().setValBytes(val);

		val.setType(ValType.ASCII);
		val.setValStr(this.getMscOutgoingROUTE());
		moCall.getMscOutgoingROUTE().getMscOutgoingRouteVal().setValBytes(val);

		String[] locationArr = this.getLocation().split(",");
		val.setType(ValType.NONE);
		val.setValStr(locationArr[0]);
		moCall.getLocation().getLac().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(locationArr[0]);
		moCall.getLocation().getCellid().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.getBasicService());
		moCall.getBasicService().getBasicServiceval().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.getMsClassmark());
		moCall.getMsClassmark().setValBytes(val);

		val.setType(ValType.TIME);
		val.setValStr(this.getSetupTime());
		moCall.getSetupTime().setValBytes(val);

		val.setType(ValType.TIME);
		val.setValStr(this.getSeizureTime());
		moCall.getSeizureTime().setValBytes(val);

		val.setType(ValType.TIME);
		val.setValStr(this.getAlertingTime());
		moCall.getAlertingTime().setValBytes(val);

		val.setType(ValType.TIME);
		val.setValStr(this.getAnswerTime());
		moCall.getAnswerTime().setValBytes(val);

		val.setType(ValType.TIME);
		val.setValStr(this.getReleaseTime());
		moCall.getReleaseTime().setValBytes(val);

		val.setType(ValType.DecToHex);
		val.setValStr(this.getCallDuration());
		moCall.getCallDuration().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.getRadioChanRequested());
		moCall.getRadioChanRequested().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.getRadioChanUsed());
		moCall.getRadioChanUsed().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.getCauseForTerm());
		moCall.getCauseForTerm().setValBytes(val);

		val.setType(ValType.TBCD);
		val.setPrefix("00");
		val.setValStr(this.getDiagnostics());
		moCall.getDiagnostics().getDiagnosticsVal().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.getCallReference());
		moCall.getCallReference().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.getAdditionalChgInfo());
		moCall.getAdditionalChgInfo().getAdditionalChgInfoval().setValBytes(val);

		val.setType(ValType.TBCD);
		val.setPrefix("91");
		val.setValStr(this.gsmSCFAddress);
		moCall.getGsmSCFAddress().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.serviceKey);
		moCall.getServiceKey().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.getNetworkCallReference());
		moCall.getNetworkCallReference().setValBytes(val);

		val.setType(ValType.TBCD);
		val.setPrefix("91");
		val.setValStr(this.getmSCAddress());
		moCall.getmSCAddress().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.getSpeechVersionSupported());
		moCall.getSpeechVersionSupported().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.getSpeechVersionUsed());
		moCall.getSpeechVersionUsed().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.numberOfDPEncountered);
		moCall.getNumberOfDPEncountered().setValBytes(val);

		val.setType(ValType.TBCD);
		val.setPrefix("05");
		val.setValStr(this.levelOfCAMELService);
		moCall.getLevelOfCAMELService().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.getSystemType());
		moCall.getSystemType().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.classmark3);
		moCall.getClassmark3().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.getChargedParty());
		moCall.getChargedParty().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.mscOutgoingCircuit);
		moCall.getMscOutgoingCircuit().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.getOrgRNCorBSCId());
		moCall.getOrgRNCorBSCId().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.getOrgMSCId());
		moCall.getOrgMSCId().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.getGlobalAreaID());
		moCall.getGlobalAreaID().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.getSubscriberCategory());
		moCall.getSubscriberCategory().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.getFirstmccmnc());
		moCall.getFirstmccmnc().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr(this.lastmccmnc);
		moCall.getLastmccmnc().setValBytes(val);

		val.setType(ValType.NONE);
		val.setValStr("00");
		moCall.geteCategory().setValBytes(val);
		return moCall;
	}
	
}
